



$(document).ready(function(){
    $.ajax({
        type: 'POST',
        url: './user.php?m=islogin',
        data: {m:'islogin'},
        success: function(data){
            var data = eval("("+data+")");
            if(data.a==='1'){
                var user=data.b;
                $("#body").remove();
                $("#newuser").remove();
                $("#loginForm").append("<p id='newuser'>欢迎"+user+"登录</p><fieldset id='body'><input type='submit' id='loginout' value='Login out' ></fieldset><br/>");
                $("#loginout").click(function(){
                    login();
                    return false;
                });
            }
        }
    });
})

$(document).ready(function(){
    $("#login").click(function(){
        var user=$("#user").val();
        var password=$("#passwd").val();
        if(user==''||password==''){
            window.alert('请输入完整的账号密码');
        }
        else{
            //window.alert('账号是:'+name+'密码是:'+password);
            $.ajax({
                type: "POST",
                url: "./user.php?m=login",
                data: {user:user,password:password},
                success: function(data){
                    var data = eval("("+data+")");
                        //window.alert(data);
                        //window.alert(data.a);
                        if(data.a==='1'){
                            window.alert('登录成功');
                            $("#body").remove();
                            $("#newuser").remove();
                            $("#loginForm").append("<p id='newuser'>欢迎"+user+"登录</p><fieldset id='body'><input type='submit' id='loginout' value='Login out' ></fieldset><br/>");
                            $("#loginout").click(function(){
                                login();
                                return false;
                            });
                        }else{
                            window.alert(data['b']);
                        }
                    }
                });
        }
        return false;
    });
});


var login=function(){
    $.ajax({
        type: 'POST',
        url: './user.php?m=out',
        data: {m:'out'},
        success: function(data){
            var data = eval("("+data+")");
            if(data.a==='1'){
                window.alert('退出成功');
                $("#body").remove();
                $("#newuser").remove();
                $("#loginForm").append("<fieldset id='body'><fieldset><label for='email'>Email Address</label><input id='user' type='text' name='email' id='email'></fieldset><fieldset><label id='password' for='password'>Password</label><input type='password' name='password' id='passwd'></fieldset><input type='submit' id='login' value='Sign in' ><label for='checkbox'><input type='checkbox' id='checkbox'> <i>Remember me</i></label></fieldset><p id='newuser'>New User ? <a class='sign' href='account.html'>Sign Up</a> <span><a href='#'>Forgot your password?</a></span></p>");
            }
        }
    });
    return false;
}

$(document).ready(function(){
    $('.addcart').click(function(){
        var num = $('#quantity').val();
        var cake_id = $('.addcart').attr('id');

        $.ajax({
            type: 'POST',
            url: "./cart.php?m=add",
            data:{cake_id:cake_id,num:num},
            success: function(data){
                var data =eval("("+data+")");
                $(".simpleCart_total").html(' ¥'+data.price+'.00');
                $(".simpleCart_quantity").html(data.num);
            }
        });

return false;
    });


});
